package com.fingard.dsp.bank.directbank.lcbip01;

import java.sql.Connection;
import java.util.Map;

import com.fingard.FGBiz;
import com.fingard.db.JDBCHelper;
import com.fingard.dsp.bank.directbank.bankInterface.IElecBillQuery;
import com.fingard.dsp.bank.reqrespobj.elecbillquery.*;
import com.fingard.dsp.bank.reqrespobj.elecbillquery.detail.ReqB006BillStateQryDetail;
import com.fingard.dsp.bank.reqrespobj.elecbillquery.detail.RetAtsB001OperBillQryDetail;
import com.fingard.dsp.bank.reqrespobj.elecbillquery.detail.RetAtsB005BillBackQryDetail;
import com.fingard.dsp.bank.reqrespobj.elecbillquery.detail.RetAtsB006BillStateQryDetail;
import com.fingard.text.StringHelper;
import com.fingard.util.DateHelper;
import com.fingard.xml.XmlTextReader;
import com.fingard.xml.XmlTextWriter;

/**
 * Created by F on 2018/9/18.
 */
public class LCBIP01ElecBill extends LCBIP01Base implements IElecBillQuery {
    private static final String SELECTRECEIPT = "SELECT TRANSDATE,REQSEQID,BANKREQSEQID FROM REQSEQIDMAPPING WHERE REQSEQID=? and BANKCODE =?;";
    @Override
    public RetAtsB001OperBillQry D_OperBill_Query_Req(ReqB001OperBillQry query) throws Exception {
        RetAtsB001OperBillQry retAst = new RetAtsB001OperBillQry(query.reqHeader);
        String respCode ="";
        String respInfo ="";
        try{
            while (query.readRecord()){
                if("1".equals(query.detail.queryType)){
                    queryBillTips(query,retAst);
                }else if("2".equals(query.detail.queryType)) {
                    queryBillSign(query,retAst);
                }else if("3".equals(query.detail.queryType)&&"1".equals(query.detail.busiType)){
                    queryBillCancel(query,retAst);
                }else if("3".equals(query.detail.queryType)){
//                    BillExceptionQueryYs(query,retAst);
                    throw new Exception("撤销类的查询暂时不支持");
                }
            }
        }catch (Exception ex){
            ex.printStackTrace();
            respCode = "-1";
            respInfo = ex.getMessage();
        }
        if("-1".equals(respCode)){
            retAst = new RetAtsB001OperBillQry(query.reqHeader);
            retAst.respCode = "-1";
            retAst.respInfo  = respInfo;
            retAst.writeBefore();
        }
        retAst.writeEnd();
        return retAst;
    }
    //查回可以持票撤回的票据
    private void BillExceptionQueryYs(ReqB001OperBillQry query, RetAtsB001OperBillQry retAst)throws Exception {
        int readNum  =0;
        int totelNum = -1;
        while (readNum<totelNum || totelNum==-1) {
            XmlTextWriter xmlTextWriter = new XmlTextWriter();
            LCBIP01Header header = new LCBIP01Header();
            header.ReqSeqNo = getQryTransID();
            header.TuxName = "BillExceptionQueryYs";
            writeCommonHeader(xmlTextWriter, header);
//            xmlTextWriter.writeElementString("ReqReserved1", 0+"", true);
            xmlTextWriter.writeElementString("ReqReserved1", readNum + "", true);
            String pageNum = getBankConfig().getValueAsString("pageNum");
            xmlTextWriter.writeElementString("ReqReserved2", pageNum, true);
            xmlTextWriter.writeElementString("ReqReserved3", "", true);
            xmlTextWriter.writeElementString("ReqReserved4", "", true);
            xmlTextWriter.writeEndElement();
            xmlTextWriter.writeStartElement("body");
//                客户编号	CustCode	Y	集团签约模式：企业直连对接系统内部编号/财务公司编号
//                非集团签约模式：财务公司编号
            xmlTextWriter.writeElementString("CustCode", bankFront.org);
//                查询类型	QueryType	Y	01:开票
            xmlTextWriter.writeElementString("QueryType", "01");
//                票据类型	BillType	N	1：银行承兑汇票 2：商业承兑汇票
            xmlTextWriter.writeElementString("BillType", query.detail.billType);
//                票据形式	Pjxs	N	0: 纸质票据 1: 电子票据
            xmlTextWriter.writeElementString("Pjxs", "1", true);
            xmlTextWriter.writeElementString("BillCode", "", true);
            xmlTextWriter.writeElementString("SDate", "20181205", true);
            xmlTextWriter.writeElementString("EDate", "20181205", true);
            xmlTextWriter.writeElementString("EndSDate", "", true);
            xmlTextWriter.writeElementString("EndEDate", "", true);
            xmlTextWriter.writeElementString("SAmt", "", true);
            xmlTextWriter.writeElementString("EAmt", "", true);
//                票据状态	BillState	N	02库存
            xmlTextWriter.writeElementString("Kpzbnm", "", true);
            xmlTextWriter.writeElementString("Skrqc", "", true);
            xmlTextWriter.writeElementString("BillState", "",true);
            xmlTextWriter.writeElementString("ReqReserved1", "", true);
            xmlTextWriter.writeElementString("ReqReserved2", "", true);
            xmlTextWriter.writeElementString("ReqReserved3", "", true);
            xmlTextWriter.writeElementString("ReqReserved4", "", true);
            xmlTextWriter.writeEndDocument();
            String[] result = sendToBank(xmlTextWriter.toXmlString());
            if (result[0].length() == 0) {
                StringBuilder tmpsbMsg = new StringBuilder();
                XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpsbMsg);
                if (tmpbkReader != null) {
                    String returnCode = tmpbkReader.getFirstText("/lcbank/head/RespCode");
                    String returnInfo = tmpbkReader.getFirstText("/lcbank/head/RespInfo");
                    if ("0".equals(returnCode)) {
                        if (StringHelper.isNullOrEmpty(retAst.respCode)) {
                            retAst.respCode = "0";
                            retAst.respInfo = returnInfo;
                            retAst.writeBefore();
                        }

                        if (totelNum == -1) {
                            String totalNumStr = tmpbkReader.getFirstText("/lcbank/body/BillInfoRespParam/ReqReserved1");
                            if(StringHelper.hasAnyChar(totalNumStr)) {
                                totelNum = Integer.valueOf(totalNumStr);
                            }else {
                                break;
                            }
                        }

                        while (tmpbkReader.read("/lcbank/body/BillInfoRespParam")) {
                            readNum++;
//                            票据形式	Pjxs	String	0: 纸质票据 1: 电子票据
                            String Pjxs = tmpbkReader.readedXElement.getSingleText("Pjxs");
//                            	是否可撤票；0：否1是
                            String ReqReserved2  = tmpbkReader.readedXElement.getSingleText("ReqReserved2");
                            if("1".equals(Pjxs)||"1".equals(ReqReserved2)) {
                                RetAtsB001OperBillQryDetail detail = new RetAtsB001OperBillQryDetail();
//                            票据编号	Pjbh	String
                                detail.billNo = tmpbkReader.readedXElement.getSingleText("Pjbh");
//                            票据合同号	BillContNo	String
                                detail.contractNo = tmpbkReader.readedXElement.getSingleText("BillContNo");
//                            票据类型	BillType	String	1：银行承兑汇票 2：商业承兑汇票
                                if("1".equals(tmpbkReader.readedXElement.getSingleText("BillType"))) {
                                    detail.billType ="EM001";
                                }else if("2".equals(tmpbkReader.readedXElement.getSingleText("BillType"))) {
                                    detail.billType ="EM002";
                                }
//                            票面金额	Pmje	String
                                detail.billAmt = tmpbkReader.readedXElement.getSingleText("Pmje");
//                            开票日期	Kprq	String
                                detail.issDate = DateHelper.convertD8toD10(tmpbkReader.readedXElement.getSingleText("Kprq"));
//                            到期日期	Dqrq	String
                                detail.dueDate =DateHelper.convertD8toD10(tmpbkReader.readedXElement.getSingleText("Dqrq"));
//                            可转让标记	Kzrbj	String	EM00:可再转让 EM01:不得转让
                                String transflag = tmpbkReader.readedXElement.getSingleText("Kzrbj");
                                if("EM00".equals(transflag)){
                                    detail.transFlag = "0";
                                }else{
                                    detail.transFlag = "1";                                }
//                            出票人名称	Cprqc	String
                                detail.drawName = tmpbkReader.readedXElement.getSingleText("Cprqc");
//                            出票人开户行	KhhName	String
                                detail.drawBnkName = tmpbkReader.readedXElement.getSingleText("KhhName");
//                            收款人名称	Skrqc	String
                                detail.receName= tmpbkReader.readedXElement.getSingleText("Skrqc");
//                            收款人开户行	Skkhh	String
                                detail.receBnkName = tmpbkReader.readedXElement.getSingleText("Skkhh");
//                            收款人账号	Skrzh	String
                                detail.receAct =  tmpbkReader.readedXElement.getSingleText("Skrzh");
//                            承兑人	CdyhName	String
                                detail.accpName = tmpbkReader.readedXElement.getSingleText("CdyhName");
                                retAst.writeDetail(detail);
                            }
                        }
                    } else {
                        throw new Exception(returnInfo);
                    }
                } else {
                    throw new Exception(tmpsbMsg.toString());
                }
            } else {
                throw new Exception(result[1]);
            }
        }
    }

    private void queryBillCancel(ReqB001OperBillQry query, RetAtsB001OperBillQry retAst) throws Exception{
        int readNum  =0;
        int totelNum = -1;
        while (readNum<totelNum || totelNum==-1) {
            XmlTextWriter xmlTextWriter = new XmlTextWriter();
            LCBIP01Header header = new LCBIP01Header();
            header.ReqSeqNo = getQryTransID();
            header.TuxName = "QueryBillInfor";
            writeCommonHeader(xmlTextWriter, header);
//            xmlTextWriter.writeElementString("ReqReserved1", 0+"", true);
            xmlTextWriter.writeElementString("ReqReserved1", readNum + "", true);
            String pageNum = getBankConfig().getValueAsString("pageNum");
            xmlTextWriter.writeElementString("ReqReserved2", pageNum, true);
            xmlTextWriter.writeElementString("ReqReserved3", "", true);
            xmlTextWriter.writeElementString("ReqReserved4", "", true);
            xmlTextWriter.writeEndElement();
            xmlTextWriter.writeStartElement("body");
//                客户编号	CustCode	Y	集团签约模式：企业直连对接系统内部编号/财务公司编号
//                非集团签约模式：财务公司编号
            xmlTextWriter.writeElementString("CustCode", bankFront.org);
//                查询类型	QueryType	Y	01:开票
            xmlTextWriter.writeElementString("QueryType", "01");
//                票据类型	BillType	N	1：银行承兑汇票 2：商业承兑汇票
            xmlTextWriter.writeElementString("BillType", query.detail.billType);
//                票据形式	Pjxs	N	0: 纸质票据 1: 电子票据
            xmlTextWriter.writeElementString("Pjxs", "1", true);
            xmlTextWriter.writeElementString("BillCode", "", true);
            xmlTextWriter.writeElementString("SDate", "", true);
            xmlTextWriter.writeElementString("EDate", "", true);
            xmlTextWriter.writeElementString("EndSDate", "", true);
            xmlTextWriter.writeElementString("EndEDate", "", true);
            xmlTextWriter.writeElementString("SAmt", "", true);
            xmlTextWriter.writeElementString("EAmt", "", true);
//                票据状态	BillState	N	02库存
            xmlTextWriter.writeElementString("Kpzbnm", "", true);
            xmlTextWriter.writeElementString("Skrqc", "", true);
            xmlTextWriter.writeElementString("BillState", "",true);
            xmlTextWriter.writeElementString("ReqReserved1", "", true);
            xmlTextWriter.writeElementString("ReqReserved2", "", true);
            xmlTextWriter.writeElementString("ReqReserved3", "", true);
            xmlTextWriter.writeElementString("ReqReserved4", "", true);
            xmlTextWriter.writeEndDocument();
            String[] result = sendToBank(xmlTextWriter.toXmlString());
            if (result[0].length() == 0) {
                StringBuilder tmpsbMsg = new StringBuilder();
                XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpsbMsg);
                if (tmpbkReader != null) {
                    String returnCode = tmpbkReader.getFirstText("/lcbank/head/RespCode");
                    String returnInfo = tmpbkReader.getFirstText("/lcbank/head/RespInfo");
                    if ("0".equals(returnCode)) {
                        if (StringHelper.isNullOrEmpty(retAst.respCode)) {
                            retAst.respCode = "0";
                            retAst.respInfo = returnInfo;
                            retAst.writeBefore();
                        }

                        if (totelNum == -1) {
                            String totalNumStr = tmpbkReader.getFirstText("/lcbank/body/BillInfoRespParam/ReqReserved1");
                            if(StringHelper.hasAnyChar(totalNumStr)) {
                                totelNum = Integer.valueOf(totalNumStr);
                            }else {
                                break;
                            }
                        }

                        while (tmpbkReader.read("/lcbank/body/BillInfoRespParam")) {
                            readNum++;
//                            票据形式	Pjxs	String	0: 纸质票据 1: 电子票据
                            String Pjxs = tmpbkReader.readedXElement.getSingleText("Pjxs");
//                            	是否可撤票；0：否1是
                            String ReqReserved2  = tmpbkReader.readedXElement.getSingleText("ReqReserved2");
                            if("1".equals(Pjxs)&&"1".equals(ReqReserved2)) {
                                RetAtsB001OperBillQryDetail detail = new RetAtsB001OperBillQryDetail();
//                            票据编号	Pjbh	String
                                detail.billNo = tmpbkReader.readedXElement.getSingleText("Pjbh");
//                            票据合同号	BillContNo	String
                                detail.contractNo = tmpbkReader.readedXElement.getSingleText("BillContNo");
//                            票据类型	BillType	String	1：银行承兑汇票 2：商业承兑汇票
                                if("1".equals(tmpbkReader.readedXElement.getSingleText("BillType"))) {
                                    detail.billType ="EM001";
                                }else if("2".equals(tmpbkReader.readedXElement.getSingleText("BillType"))) {
                                    detail.billType ="EM002";
                                }
//                            票面金额	Pmje	String
                                detail.billAmt = tmpbkReader.readedXElement.getSingleText("Pmje");
//                            开票日期	Kprq	String
                                detail.issDate = DateHelper.convertD8toD10(tmpbkReader.readedXElement.getSingleText("Kprq"));
//                            到期日期	Dqrq	String
                                detail.dueDate =DateHelper.convertD8toD10(tmpbkReader.readedXElement.getSingleText("Dqrq"));
//                            可转让标记	Kzrbj	String	EM00:可再转让 EM01:不得转让
                                String transflag = tmpbkReader.readedXElement.getSingleText("Kzrbj");
                                if("EM00".equals(transflag)){
                                    detail.transFlag = "0";
                                }else{
                                    detail.transFlag = "1";                                }
//                            出票人名称	Cprqc	String
                                detail.drawName = tmpbkReader.readedXElement.getSingleText("Cprqc");
//                            出票人开户行	KhhName	String
                                detail.drawBnkName = tmpbkReader.readedXElement.getSingleText("KhhName");
//                            收款人名称	Skrqc	String
                                detail.receName= tmpbkReader.readedXElement.getSingleText("Skrqc");
//                            收款人开户行	Skkhh	String
                                detail.receBnkName = tmpbkReader.readedXElement.getSingleText("Skkhh");
//                            收款人账号	Skrzh	String
                                detail.receAct =  tmpbkReader.readedXElement.getSingleText("Skrzh");
//                            承兑人	CdyhName	String
                                detail.accpName = tmpbkReader.readedXElement.getSingleText("CdyhName");
                                retAst.writeDetail(detail);
                            }
                        }
                    } else {
                        throw new Exception(returnInfo);
                    }
                } else {
                    throw new Exception(tmpsbMsg.toString());
                }
            } else {
                throw new Exception(result[1]);
            }
        }
    }

    private void queryBillSign(ReqB001OperBillQry query, RetAtsB001OperBillQry retAst) throws Exception {
        int readNum  =0;
        int totelNum = -1;
        while (readNum<totelNum || totelNum==-1) {
            XmlTextWriter xmlTextWriter = new XmlTextWriter();
            LCBIP01Header header = new LCBIP01Header();
            header.ReqSeqNo = getQryTransID();
            header.TuxName = "QueryBillSign";
            writeCommonHeader(xmlTextWriter, header);
            //        备用字段1	 ReqReserved1 //当前条数
            xmlTextWriter.writeElementString("ReqReserved1", "" + readNum, true);
//        备用字段2	ReqReserved2ReqReserved2 //每页显示条数，默认显示50条
            String pageNum = getBankConfig().getValueAsString("pageNum");
            xmlTextWriter.writeElementString("ReqReserved2", pageNum, true);
            xmlTextWriter.writeElementString("ReqReserved3", "", true);
            xmlTextWriter.writeElementString("ReqReserved4", "", true);
            xmlTextWriter.writeEndElement();
            xmlTextWriter.writeStartElement("body");
//        客户编号	CustCode	Y	集团签约模式：企业直连对接系统内部编号/财务公司编号
//        非集团签约模式：财务公司编号
            xmlTextWriter.writeElementString("CustCode", bankFront.org);
//        业务类型	BznsType	N	03:正常收票,02:提示承兑,10:背书转让,19:质押解除,17:保证,12:贴现赎回,23:同意清偿
            int busiType = Integer.valueOf(query.detail.busiType);
            String bznsType;
            switch (busiType) {
                case 2:
                    bznsType = "02";
                    break;
                case 3:
                    bznsType = "03";
                    break;
                case 4:
                    bznsType = "10";
                    break;
                case 6:
                    bznsType = "19";
                    break;
                case 11:
                    bznsType = "12";
                    break;
                case 14:
                    bznsType = "23";
                    break;
                default:
                    throw new Exception("未知的业务类型：" + query.detail.busiType);
            }
            xmlTextWriter.writeElementString("BznsType", bznsType);
//        票面金额起始	BillAmtS	N
            xmlTextWriter.writeElementString("BillAmtS", "", true);
//        票面金额截止	BillAmtE	N
            xmlTextWriter.writeElementString("BillAmtE", "", true);
//        票据类型	BillType	N	1：银行承兑汇票
//        2：商业承兑汇票
            xmlTextWriter.writeElementString("BillType", query.detail.billType);
//        票据编号	BillCode	N	30位电票编号
            xmlTextWriter.writeElementString("BillCode", "", true);
//        到期日期开始日期	StartBusiDate	N	示例：20180101
            xmlTextWriter.writeElementString("StartBusiDate", "", true);
//        到期日期截止日期		N	示例：20180101
            xmlTextWriter.writeElementString("EndBusiDate", "", true);
            xmlTextWriter.writeElementString("ReqReserved1", "", true);
            xmlTextWriter.writeElementString("ReqReserved2", "", true);
//        备用字段3	ReqReserved3
            xmlTextWriter.writeElementString("ReqReserved3", "", true);
//        备用字段4	ReqReserved4
            xmlTextWriter.writeElementString("ReqReserved4", "", true);
            xmlTextWriter.writeEndDocument();
            String[] result = sendToBank(xmlTextWriter.toXmlString());
            if (result[0].length() == 0) {
                StringBuilder tmpsbMsg = new StringBuilder();
                XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpsbMsg);
                if (tmpbkReader != null) {
                    String returnCode = tmpbkReader.getFirstText("/lcbank/head/RespCode");
                    String returnInfo = tmpbkReader.getFirstText("/lcbank/head/RespInfo");
                    if ("0".equals(returnCode)) {
                            if (StringHelper.isNullOrEmpty(retAst.respCode)) {
                                retAst.respCode = "0";
                                retAst.respInfo = returnInfo;
                                retAst.writeBefore();
                            }
                        if (totelNum == -1) {
                            String totalNumStr = tmpbkReader.getFirstText("/lcbank/body/BillSignRespParam/ReqReserved1");
                            if(StringHelper.hasAnyChar(totalNumStr)) {
                                totelNum = Integer.valueOf(totalNumStr);
                            }else {
                                break;
                            }
                        }
                        while (tmpbkReader.read("/lcbank/body/BillSignRespParam")) {
                            readNum++;
                            if(!"00".equals(tmpbkReader.readedXElement.getSingleText("Status"))){
                                continue;
                            }
//                            待签收人账号	RecAcc	String
                            String recAcc = tmpbkReader.readedXElement.getSingleText("RecAcc");
                            if(query.detail.actNum.equals(recAcc)){
                                continue;
                            }
                            RetAtsB001OperBillQryDetail detail = new RetAtsB001OperBillQryDetail();
//                        票据编号	BillCode	String
                            detail.billNo = tmpbkReader.readedXElement.getSingleText("BillCode");
//                        票据类型	BillType	String	1：银行承兑汇票
//                        2：商业承兑汇票
                            if("1".equals(tmpbkReader.readedXElement.getSingleText("BillType"))) {
                                detail.billType ="EM001";
                            }else if("2".equals(tmpbkReader.readedXElement.getSingleText("BillType"))) {
                                detail.billType ="EM002";
                            }
//                        票面金额	BillAmt	String
                            detail.billAmt = tmpbkReader.readedXElement.getSingleText("BillAmt");
//                        对方单位名称	ForeEndorseName	String
                            detail.applyName = tmpbkReader.readedXElement.getSingleText("ForeEndorseName");
//                        对方账户	ForeEndorseAcc	String
                            detail.applyAct = tmpbkReader.readedXElement.getSingleText("ForeEndorseAcc");
//                        对方所属银行行号	ForeEndorseBankno	String
                            detail.applyBnkCode = tmpbkReader.readedXElement.getSingleText("ForeEndorseBankno");
//                        对方所属银行	ForeEndorseBankname	String
                            detail.applyBnkName = tmpbkReader.readedXElement.getSingleText("ForeEndorseBankname");
//                        是否可转让	TransferFlag	String	可再转让：EM00
//                        不得转让：EM01
                            String transferFlag = tmpbkReader.readedXElement.getSingleText("TransferFlag");
                            if ("EM00".equals(transferFlag)) {
                                detail.transFlag = "1";
                            } else if ("EM01".equals(transferFlag)) {
                                detail.transFlag = "0";
                            }
//                        状态	Status	String	00:待签收,01:网银经办,02:网银提交,03:网银复核通过,04:网银复核退回
//                        待签收人全称	CustName	String
                            detail.receName = tmpbkReader.readedXElement.getSingleText("CustName");
                            //单据编号
                            detail.busiNo = tmpbkReader.readedXElement.getSingleText("TosignNm");
//                        出票日期	StartDate	String
                            detail.issDate = tmpbkReader.readedXElement.getSingleText("StartDate");
//                        到期日期	EndDate	String
                            detail.dueDate = tmpbkReader.readedXElement.getSingleText("EndDate");
//                        出票人全称	DrawName	String
                            detail.drawName = tmpbkReader.readedXElement.getSingleText("DrawName");
//                        出票人账号	DrawAcc	String
                            detail.drawAct = tmpbkReader.readedXElement.getSingleText("DrawAcc");
//                        出票人开户行	DrawBankName	String
                            detail.drawBnkName = tmpbkReader.readedXElement.getSingleText("DrawBankName");
//                        承兑人全称	AceptoeBankName	String
                            detail.accpName = tmpbkReader.readedXElement.getSingleText("AceptoeBankName");
//                        收票人全称	FirstRecName	String
                            detail.payeeName = tmpbkReader.readedXElement.getSingleText("FirstRecName");
//                        收票人账号	FirstRecAcc	String
                            detail.payeeAct = tmpbkReader.readedXElement.getSingleText("FirstRecAcc");
//                        收票人开户行	FirstRecBankname	String
                            detail.payeeBnkName = tmpbkReader.readedXElement.getSingleText("FirstRecBankname");
//                        备注	PromptMemo	String
                            detail.memo = tmpbkReader.readedXElement.getSingleText("PromptMemo");
                            detail.billStatus = tmpbkReader.readedXElement.getSingleText("Status");
                            retAst.writeDetail(detail);
                        }
                    } else {
                        throw new Exception(returnInfo);
                    }
                } else {
                    throw new Exception(tmpsbMsg.toString());
                }
            } else {
                throw new Exception(result[1]);
            }
        }
    }

    private void queryBillTips(ReqB001OperBillQry query, RetAtsB001OperBillQry retAst)throws Exception {
        if(!"4".equals(query.detail.busiType)&&!"5".equals(query.detail.busiType)
                &&!"10".equals(query.detail.busiType) &&!"12".equals(query.detail.busiType)){
            throw new Exception("银行不支持该业务类型的持票查询！");
        }
        int readNum  =0;
        int totelNum = -1;
        while (readNum<totelNum || totelNum==-1) {
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
                LCBIP01Header header = new LCBIP01Header();
                header.ReqSeqNo = getQryTransID();
                header.TuxName = "QueryBillTips";
                writeCommonHeader(xmlTextWriter, header);
//            xmlTextWriter.writeElementString("ReqReserved1", 0+"", true);
                xmlTextWriter.writeElementString("ReqReserved1", readNum + "", true);
                String pageNum = getBankConfig().getValueAsString("pageNum");
                xmlTextWriter.writeElementString("ReqReserved2", pageNum, true);
                xmlTextWriter.writeElementString("ReqReserved3", "", true);
                xmlTextWriter.writeElementString("ReqReserved4", "", true);
                xmlTextWriter.writeEndElement();
                xmlTextWriter.writeStartElement("body");
//                客户编号	CustCode	Y	集团签约模式：企业直连对接系统内部编号/财务公司编号
//                非集团签约模式：财务公司编号
                xmlTextWriter.writeElementString("CustCode", bankFront.org);
//                查询类型	QueryType	Y	01:开票
                xmlTextWriter.writeElementString("QueryType", "00");
//                票据类型	BillType	N	1：银行承兑汇票 2：商业承兑汇票
                xmlTextWriter.writeElementString("BillType", query.detail.billType);
//                票据形式	Pjxs	N	0: 纸质票据 1: 电子票据
                xmlTextWriter.writeElementString("Pjxs", "1", true);
                xmlTextWriter.writeElementString("BillCode", "", true);
                xmlTextWriter.writeElementString("SDate", "", true);
                xmlTextWriter.writeElementString("EDate", "", true);
                xmlTextWriter.writeElementString("EndSDate", "", true);
                xmlTextWriter.writeElementString("EndEDate", "", true);
                xmlTextWriter.writeElementString("SAmt", "", true);
                xmlTextWriter.writeElementString("EAmt", "", true);
                xmlTextWriter.writeElementString("AccountSDate", "", true);
                xmlTextWriter.writeElementString("AccountEDate", "", true);
//                票据状态	BillState	N	02库存
                xmlTextWriter.writeElementString("BillState", "02");
                xmlTextWriter.writeElementString("SafekeepStatus", "", true);
                xmlTextWriter.writeElementString("StackPlace", "", true);
//                持票人账号	RecAcc	N
                xmlTextWriter.writeElementString("RecAcc", query.detail.actNum);
//        xmlTextWriter.writeElementString("RecAcc","",true);
                xmlTextWriter.writeElementString("ReqReserved1", "", true);
//            String pageNum = getBankConfig().getValueAsString("pageNum");
                xmlTextWriter.writeElementString("ReqReserved2", "", true);
                xmlTextWriter.writeElementString("ReqReserved3", "", true);
                xmlTextWriter.writeElementString("ReqReserved4", "", true);
                xmlTextWriter.writeEndDocument();
                String[] result = sendToBank(xmlTextWriter.toXmlString());
                if (result[0].length() == 0) {
                    StringBuilder tmpsbMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpsbMsg);
                    if (tmpbkReader != null) {
                        String returnCode = tmpbkReader.getFirstText("/lcbank/head/RespCode");
                        String returnInfo = tmpbkReader.getFirstText("/lcbank/head/RespInfo");
                        if ("0".equals(returnCode)) {
                            if (StringHelper.isNullOrEmpty(retAst.respCode)) {
                                retAst.respCode = "0";
                                retAst.respInfo = returnInfo;
                                retAst.writeBefore();
                            }

                            if (totelNum == -1) {
                                String totalNumStr = tmpbkReader.getFirstText("/lcbank/body/BillRecInfoRespParam/ReqReserved1");
                                if(StringHelper.hasAnyChar(totalNumStr)) {
                                    totelNum = Integer.valueOf(totalNumStr);
                                }else {
                                    break;
                                }
                            }
                            while (tmpbkReader.read("/lcbank/body/BillRecInfoRespParam")) {
                                readNum++;
                                RetAtsB001OperBillQryDetail detail = new RetAtsB001OperBillQryDetail();
//                                票据编号	Pjbh	Strin
                                detail.billNo = tmpbkReader.readedXElement.getSingleText("Pjbh");
//                            票据类型	BillType	String	1：银行承兑汇票
//                            2：商业承兑汇票
                                if("1".equals(tmpbkReader.readedXElement.getSingleText("BillType"))) {
                                    detail.billType ="EM001";
                                }else if("2".equals(tmpbkReader.readedXElement.getSingleText("BillType"))) {
                                    detail.billType ="EM002";
                                }
//                            票面金额	Pmje	String
                                detail.billAmt = tmpbkReader.readedXElement.getSingleText("Pmje");
//                            开票日期	Kprq	String
                                detail.issDate = DateHelper.convertD8toD10(tmpbkReader.readedXElement.getSingleText("Kprq"));
//                            到期日期	Dqrq	String
                                detail.dueDate = DateHelper.convertD8toD10(tmpbkReader.readedXElement.getSingleText("Dqrq"));
//                            出票人名称	Cprqc	String
                                detail.drawName = tmpbkReader.readedXElement.getSingleText("Cprqc");
//                            出票人账号	DrawAcc	String
                                detail.drawAct = tmpbkReader.readedXElement.getSingleText("DrawAcc");
//                            承兑行	AceptorBankName	String
                                detail.accpBnkName = tmpbkReader.readedXElement.getSingleText("AceptorBankName");
//                            上手人名称	ForeEndorseName	String
//                            票据状态	Pjzt	String	根据票据状态码值返回具体状态名称
                                detail.billStatus = tmpbkReader.readedXElement.getSingleText("Pjzt");
//                            是否可转让	TransferFlag	String	EM00:可再转让 EM01:不得转让
                                String transferFlag = tmpbkReader.readedXElement.getSingleText("TransferFlag");
                                if ("EM00".equals(transferFlag)) {
                                    detail.transFlag = "1";
                                } else if ("EM01".equals(transferFlag)) {
                                    detail.transFlag = "0";
                                }
//                            备注	Remark
                                detail.memo = tmpbkReader.readedXElement.getSingleText("Remark");
                                retAst.writeDetail(detail);
                            }
                        } else {
                            throw new Exception(returnInfo);
                        }
                    } else {
                        throw new Exception(tmpsbMsg.toString());
                    }
                } else {
                    throw new Exception(result[1]);
                }
            }
    }

    @Override
    public RetAtsB002BillTransQry D_B002_BillTrans_Query(ReqB002BillTransQry query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB004BillFrontQry D_B004_BillFront_Query(ReqB004BillFrontQry query) throws Exception {
        RetAtsB004BillFrontQry retAts = new RetAtsB004BillFrontQry(query.reqHeader);
        retAts.writeStart();
        query.readRecord();
        try {
//            if ("1".equals(query.detail.queryType)) {
//                if ("1".equals(query.detail.busiType)) {
//                    queryBillInfor(retAts, query);
//                } else if ("4".equals(query.detail.busiType) || "5".equals(query.detail.busiType)
//                        || "10".equals(query.detail.busiType) || "12".equals(query.detail.busiType)) {
//                    queryBillTips(retAts, query);
//                } else {
//                    throw new Exception("该业务无法进行状态同步:");
//                }
//            } else if ("3".equals(query.detail.queryType) && "1".equals(query.detail.busiType)) {
//                queryBillInfor(retAts, query);
//            } else {
////                throw new Exception("该业务无法进行状态同步:");
//                billInfoPrintQuery(retAts, query);
//            }
            billInfoPrintQuery(retAts, query);
        }catch (Exception ex){
            ex.printStackTrace();
            retAts = new RetAtsB004BillFrontQry(query.reqHeader);
            retAts.writeStart();
            retAts.respCode ="-1";
            retAts.respInfo = ex.getMessage();
        }
        retAts.writeRetDetail();
        retAts.writeEnd();
        return retAts;
    }
    //票据正面信息查询
    private void billInfoPrintQuery(RetAtsB004BillFrontQry retAts, ReqB004BillFrontQry query) throws Exception {
        XmlTextWriter xmlTextWriter = new XmlTextWriter();
        LCBIP01Header header = new LCBIP01Header();
        header.ReqSeqNo = getQryTransID();
        header.TuxName = "BillInfoPrintQuery";
        writeCommonHeader(xmlTextWriter,header);
        xmlTextWriter.writeEndElement();
        xmlTextWriter.writeStartElement("body");
//        客户编号	CustCode	Y	企业客户编号
        xmlTextWriter.writeElementString("CustCode",bankFront.org);
//        票据编号	BillCode	Y	30位电子票据编号
        xmlTextWriter.writeElementString("BillCode",query.detail.billNo);
//        备用字段1	reqReserved1
        xmlTextWriter.writeElementString("reqReserved1","");
//        备用字段2	reqReserved2
        xmlTextWriter.writeElementString("reqReserved2","");
//        备用字段3	reqReserved3
        xmlTextWriter.writeElementString("reqReserved3","");
//        备用字段4	reqReserved4
        xmlTextWriter.writeElementString("reqReserved4","");
        xmlTextWriter.writeEndDocument();
        String[] bankResult =sendToBank(xmlTextWriter.toXmlString());
        if (bankResult[0].length() == 0) {
            StringBuilder tmpsbMsg = new StringBuilder();
            XmlTextReader tmpbkReader = loadBankRespXmlReader(bankResult[1], tmpsbMsg);
            if (tmpbkReader != null) {
                String returnCode = tmpbkReader.getFirstText("/lcbank/head/RespCode");
                String returnInfo = tmpbkReader.getFirstText("/lcbank/head/RespInfo");
                if ("0".equals(returnCode)) {
                    retAts.respCode ="-1";
                    if (tmpbkReader.read("/lcbank/body/BillInfoQueryRespParam")){
                        retAts.respCode ="0";
//                        票据编号	BillCode	30位电子票据编号
                        retAts.billNo = tmpbkReader.readedXElement.getSingleText("BillCode");
//                        票据类型	BillType	1：银行承兑汇票 2：商业承兑汇票
                        retAts.billType = tmpbkReader.readedXElement.getSingleText("BillType");
//                        票面金额	BillAmt
                        retAts.billAmt = tmpbkReader.readedXElement.getSingleText("BillAmt");
//                        出票日期	DrawDate
                        retAts.issDate = tmpbkReader.readedXElement.getSingleText("DrawDate");
//                        到期日期	EndDate
                        retAts.dueDate = tmpbkReader.readedXElement.getSingleText("EndDate");
//                        出票人名称	DrawerName
                        retAts.drawName = tmpbkReader.readedXElement.getSingleText("DrawerName");
//                        出票人账号	DrawerAccount
                        retAts.drawAct = tmpbkReader.readedXElement.getSingleText("DrawerAccount");
//                        出票人开户行号	DrawerOppBank
                        retAts.drawBnkCode = tmpbkReader.readedXElement.getSingleText("DrawerOppBankNo");
//                        出票人开户行	DrawerOppBank
                        retAts.drawBnkName = tmpbkReader.readedXElement.getSingleText("DrawerOppBank");
//                        承兑行名称	AcceptBankName
                        retAts.accpName = tmpbkReader.readedXElement.getSingleText("AcceptBankName");
//                        承兑行行号	AcceptBankNo
                        retAts.accpBnkCode = tmpbkReader.readedXElement.getSingleText("AcceptBankNo");
//                        承兑人账号	AcceptBankAccount
                        retAts.accpAct  = tmpbkReader.readedXElement.getSingleText("AcceptBankAccount");
//                        承兑人开户行名称	AcceptOppBankName
                        retAts.accpBnkName = tmpbkReader.readedXElement.getSingleText("AcceptOppBankName");
//                        收款人名称	PayeeName
                        retAts.payeeName = tmpbkReader.readedXElement.getSingleText("PayeeName");
//                        收款人账号	PayeeAccount
                        retAts.payeeAct = tmpbkReader.readedXElement.getSingleText("PayeeAccount");
//                        收款人开户行	PayeeOppBank
                        retAts.payeeBnkName = tmpbkReader.readedXElement.getSingleText("PayeeOppBank");
//                        收款人开户行	PayeeOppBank
                        retAts.payeeBnkCode = tmpbkReader.readedXElement.getSingleText("PayeeOppBankNo");
//                        票据状态	BillStatus
                        retAts.billState = tmpbkReader.readedXElement.getSingleText("BillStatus");
//                        可转让标记	TransFlag	EM00:可再转让 EM01:不得转让
                        retAts.transFlag ="EM00".equals(tmpbkReader.readedXElement.getSingleText("TransFlag"))?"1":"0";
                    }
                } else {
                    throw new Exception(returnInfo);
                }
            }else{
                throw new Exception(tmpsbMsg.toString());
            }
        }else{
            throw new Exception(bankResult[1]);
        }
    }

    //        对持票操作进行状态同步
    public void queryBillTips(RetAtsB004BillFrontQry retAts, ReqB004BillFrontQry query) throws Exception{
             XmlTextWriter xmlTextWriter = new XmlTextWriter();
             LCBIP01Header header = new LCBIP01Header();
             header.ReqSeqNo = getQryTransID();
             header.TuxName = "QueryBillTips";
             writeCommonHeader(xmlTextWriter, header);
            xmlTextWriter.writeElementString("ReqReserved1", 0+"", true);
//             xmlTextWriter.writeElementString("ReqReserved1", "", true);
             String pageNum = getBankConfig().getValueAsString("pageNum");
             xmlTextWriter.writeElementString("ReqReserved2", pageNum, true);
             xmlTextWriter.writeElementString("ReqReserved3", "", true);
             xmlTextWriter.writeElementString("ReqReserved4", "", true);
             xmlTextWriter.writeEndElement();
             xmlTextWriter.writeStartElement("body");
//                客户编号	CustCode	Y	集团签约模式：企业直连对接系统内部编号/财务公司编号
//                非集团签约模式：财务公司编号
             xmlTextWriter.writeElementString("CustCode", bankFront.org);
//                查询类型	QueryType	Y	01:开票
             xmlTextWriter.writeElementString("QueryType", "00");
//                票据类型	BillType	N	1：银行承兑汇票 2：商业承兑汇票
             xmlTextWriter.writeElementString("BillType", query.detail.billType);
//                票据形式	Pjxs	N	0: 纸质票据 1: 电子票据
             xmlTextWriter.writeElementString("Pjxs", "1", true);
             xmlTextWriter.writeElementString("BillCode", query.detail.billNo, true);
             xmlTextWriter.writeElementString("SDate", "", true);
             xmlTextWriter.writeElementString("EDate", "", true);
             xmlTextWriter.writeElementString("EndSDate", "", true);
             xmlTextWriter.writeElementString("EndEDate", "", true);
             xmlTextWriter.writeElementString("SAmt", "", true);
             xmlTextWriter.writeElementString("EAmt", "", true);
             xmlTextWriter.writeElementString("AccountSDate", "", true);
             xmlTextWriter.writeElementString("AccountEDate", "", true);
//                票据状态	BillState	N	02库存
             xmlTextWriter.writeElementString("BillState", "");
             xmlTextWriter.writeElementString("SafekeepStatus", "", true);
             xmlTextWriter.writeElementString("StackPlace", "", true);
//                持票人账号	RecAcc	N
             xmlTextWriter.writeElementString("RecAcc", "");
//        xmlTextWriter.writeElementString("RecAcc","",true);
             xmlTextWriter.writeElementString("ReqReserved1", "", true);
//            String pageNum = getBankConfig().getValueAsString("pageNum");
             xmlTextWriter.writeElementString("ReqReserved2", "", true);
             xmlTextWriter.writeElementString("ReqReserved3", "", true);
             xmlTextWriter.writeElementString("ReqReserved4", "", true);
             xmlTextWriter.writeEndDocument();
             String[] result = sendToBank(xmlTextWriter.toXmlString());
             if (result[0].length() == 0) {
                 StringBuilder tmpsbMsg = new StringBuilder();
                 XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpsbMsg);
                 if (tmpbkReader != null) {
                     String returnCode = tmpbkReader.getFirstText("/lcbank/head/RespCode");
                     String returnInfo = tmpbkReader.getFirstText("/lcbank/head/RespInfo");
                     String totalNumStr = tmpbkReader.getFirstText("/lcbank/body/BillRecInfoRespParam/ReqReserved1");
                     if ("0".equals(returnCode)) {
                         if (!"1".equals(totalNumStr)) {
                             throw new Exception("返回数据不唯一");
                         }
                         while (tmpbkReader.read("/lcbank/body/BillRecInfoRespParam")) {
                             retAts.respCode = "0";
                             retAts.respInfo = returnInfo;
//                                票据编号	Pjbh	Strin
                             retAts.billNo = tmpbkReader.readedXElement.getSingleText("Pjbh");
//                            票据类型	BillType	String	1：银行承兑汇票
//                            2：商业承兑汇票
                             retAts.billType = tmpbkReader.readedXElement.getSingleText("BillType");
//                            票面金额	Pmje	String
                             retAts.billAmt = tmpbkReader.readedXElement.getSingleText("Pmje");
//                            开票日期	Kprq	String
                             retAts.issDate = DateHelper.convertD8toD10(tmpbkReader.readedXElement.getSingleText("Kprq"));
//                            到期日期	Dqrq	String
                             retAts.dueDate = DateHelper.convertD8toD10(tmpbkReader.readedXElement.getSingleText("Dqrq"));
//                            出票人名称	Cprqc	String
                             retAts.drawName = tmpbkReader.readedXElement.getSingleText("Cprqc");
//                            出票人账号	DrawAcc	String
                             retAts.drawAct = tmpbkReader.readedXElement.getSingleText("DrawAcc");
//                            承兑行	AceptorBankName	String
                             retAts.accpBnkName = tmpbkReader.readedXElement.getSingleText("AceptorBankName");
//                            上手人名称	ForeEndorseName	String
//                            票据状态	Pjzt	String	根据票据状态码值返回具体状态名称
                             retAts.billState = tmpbkReader.readedXElement.getSingleText("Pjzt");
//                            是否可转让	TransferFlag	String	EM00:可再转让 EM01:不得转让
                             String transferFlag = tmpbkReader.readedXElement.getSingleText("TransferFlag");
                             if ("EM00".equals(transferFlag)) {
                                 retAts.transFlag = "1";
                             } else if ("EM01".equals(transferFlag)) {
                                 retAts.transFlag = "0";
                             }
//                            备注	Remark
                         }
                     } else {
                         throw new Exception("查询异常");
                     }
                 }else{
                     throw new Exception(tmpsbMsg.toString());
                 }
             }else{
                 throw new Exception(result[1]);
             }
        }

    //  对出票和撤票的票据进行状态同步
    public void queryBillInfor(RetAtsB004BillFrontQry retAts,ReqB004BillFrontQry query) throws Exception {
            XmlTextWriter xmlTextWriter = new XmlTextWriter();
            LCBIP01Header header = new LCBIP01Header();
            header.ReqSeqNo = getQryTransID();
            header.TuxName = "QueryBillInfor";
            writeCommonHeader(xmlTextWriter, header);
            xmlTextWriter.writeElementString("ReqReserved1", "0", true);
            String pageNum = getBankConfig().getValueAsString("pageNum");
            xmlTextWriter.writeElementString("ReqReserved2", pageNum, true);
            xmlTextWriter.writeElementString("ReqReserved3", "", true);
            xmlTextWriter.writeElementString("ReqReserved4", "", true);
            xmlTextWriter.writeEndElement();
            xmlTextWriter.writeStartElement("body");
//            客户编号	CustCode	Y	集团签约模式：企业直连对接系统内部编号/财务公司编号
            xmlTextWriter.writeElementString("CustCode", bankFront.org);
//            非集团签约模式：财务公司编号
//            查询类型	QueryType	Y	01:开票
            xmlTextWriter.writeElementString("QueryType", "01");
//            票据类型	BillType	N	1：银行承兑汇票
            xmlTextWriter.writeElementString("BillType", query.detail.billType, true);
//            2：商业承兑汇票
//            票据形式	Pjxs	N	0: 纸质票据
            xmlTextWriter.writeElementString("Pjxs", "1");
//            1: 电子票据
//            票据编号	BillCode	N
            xmlTextWriter.writeElementString("BillCode", query.detail.billNo);
//            开票日期（开始区间）	SDate	N	示例：20180101
            xmlTextWriter.writeElementString("SDate", "", true);
//            开票日期（结束区间）	EDate	N	示例：20180631
            xmlTextWriter.writeElementString("EDate", "", true);
//            到期日期（开始区间）	EndSDate	N	示例：20180101
            xmlTextWriter.writeElementString("EndSDate", "", true);
//            到期日期（结束区间）	EndEDate	N	示例：20180631
            xmlTextWriter.writeElementString("EndEDate", "", true);
//            票面金额（开始区间）	SAmt	N
            xmlTextWriter.writeElementString("SAmt", "", true);
//            票面金额（结束区间）	EAmt	N
            xmlTextWriter.writeElementString("EAmt", "", true);
//            票据合同号	Kpzbnm	N
            xmlTextWriter.writeElementString("Kpzbnm", "", true);
//            收款人名称	Skrqc	N
            xmlTextWriter.writeElementString("Skrqc", "", true);
//            票据状态	BillState	N	10:开票申请,11:开票申请提交,12:开票申请复核,13:开票申请退回,14:受理拒绝,22:已开票,42:已承付,7:作废,32:到期复核
            xmlTextWriter.writeElementString("BillState", "", true);
//            备用字段1	ReqReserved1
            xmlTextWriter.writeElementString("ReqReserved1", "", true);
//            备用字段2	ReqReserved2
            xmlTextWriter.writeElementString("ReqReserved2", "", true);
//            备用字段3	ReqReserved3
            xmlTextWriter.writeElementString("ReqReserved3", "", true);
//            备用字段4	ReqReserved4
            xmlTextWriter.writeElementString("ReqReserved4", "", true);
            xmlTextWriter.writeEndDocument();
            String[] result = sendToBank(xmlTextWriter.toXmlString());
            if (result[0].length() == 0) {
                StringBuilder tmpsbMsg = new StringBuilder();
                XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpsbMsg);
                    if (tmpbkReader != null) {
                        String returnCode = tmpbkReader.getFirstText("/lcbank/head/RespCode");
                        String returnInfo = tmpbkReader.getFirstText("/lcbank/head/RespInfo");
                        String recordNum = tmpbkReader.getFirstText("/lcbank/body/BillInfoRespParam/ReqReserved1");
                        if ("0".equals(returnCode) ) {
                            if(!"1".equals(recordNum)){
                                throw new Exception("返回数据不唯一");
                            }
                            while (tmpbkReader.read("/lcbank/body/BillInfoRespParam")) {
                                retAts.respCode = "0";
                                retAts.respInfo = returnInfo;
//                            票据申请编号	AppId	String
//                            票据编号	Pjbh	String
                                retAts.billNo = tmpbkReader.readedXElement.getSingleText("Pjbh");
//                            票据类型	BillType	String	1：银行承兑汇票
//                            2：商业承兑汇票
                                retAts.billType = tmpbkReader.readedXElement.getSingleText("BillType");
//                            票面金额	Pmje	String
                                retAts.billAmt = tmpbkReader.readedXElement.getSingleText("Pmje");
//                            开票日期	Kprq	String
                                retAts.issDate = tmpbkReader.readedXElement.getSingleText("Kprq");
//                            到期日期	Dqrq	String
                                retAts.dueDate = tmpbkReader.readedXElement.getSingleText("Dqrq");
//                            可转让标记	Kzrbj	String
                                String transFlag = tmpbkReader.readedXElement.getSingleText("Kzrbj");
                                if ("EM00".equals(transFlag)) {
                                    transFlag = "1";
                                } else if ("EM01".equals(transFlag)) {
                                    transFlag = "0";
                                }
                                retAts.transFlag = transFlag;
//                            出票人编号	Kpdw	String
//                            出票人名称	Cprqc	String
                                retAts.drawName = tmpbkReader.readedXElement.getSingleText("Cprqc");
//                            出票人开户行	KhhName	String
                                String khhName = tmpbkReader.readedXElement.getSingleText("KhhName");
                                if ("99".equals(khhName)) {
                                    retAts.drawBnkName = "兵器装备集团财务有限责任公司";
                                } else {
                                    retAts.drawBnkName = khhName;
                                }
//                            出票人往来户	Cprxhh	String
//                            出票人保证金户	Cprbzjh	String
//                            收款人名称	Skrqc	String
                                retAts.payeeName = tmpbkReader.readedXElement.getSingleText("Skrqc");
//                            收款人开户行	Skkhh	String
                                retAts.payeeBnkName = tmpbkReader.readedXElement.getSingleText("Skkhh");
//                            收款人账号	Skrzh	String
                                retAts.payeeAct = tmpbkReader.readedXElement.getSingleText("Skrzh");
//                            持票人名称	HolderName	String
//                            持票人账号	HolderAcct	String
//                            持票人开户行	HolderBankName	String
//                            授信编号	CustCreditNo	String
//                            手续费	Fee	String
//                            手续费率（‰）	FeeRate	String
//                            保证金金额	Bzj	String
//                            保证金比例(%)	Bzjbl	String
//                            剩余天数	RemainDays	String
//                            票据状态	Pjzt	String	根据票据状态码值返回具体状态名称
                                retAts.billState = tmpbkReader.readedXElement.getSingleText("Pjzt");
//                            撤票状态	Cxzt	String	根据撤票状态码值返回具体状态名称
//                            承兑状态	Cdzt	String	根据承兑状态码值返回具体状态名称
//                            提示收票状态	Spzt	String	根据提票收票状态码值返回具体状态名称
//                            撤销时间	CancelDate	String
//                            承兑人	CdyhName	String
                                retAts.accpName = tmpbkReader.readedXElement.getSingleText("CdyhName");
                            }
                        }else{
                            throw new Exception("查询异常："+returnInfo);
                        }
                }else{
                    throw new Exception(tmpsbMsg.toString());
                }
            }else{
                throw  new Exception(result[1]);
            }
        }


    @Override
    public RetAtsB005BillBackQry D_B005_BillBack_Query(ReqB005BillBackQry query) throws Exception {
        RetAtsB005BillBackQry retAts  = new RetAtsB005BillBackQry(query.reqHeader);
        retAts.writeStart();
        query.readRecord();
        try {
            XmlTextWriter xmlTextWriter = new XmlTextWriter();
            LCBIP01Header header = new LCBIP01Header();
            header.ReqSeqNo = getQryTransID();
            header.TuxName = "BillInfoPrintQuery";
            writeCommonHeader(xmlTextWriter,header);
            xmlTextWriter.writeEndElement();
            xmlTextWriter.writeStartElement("body");
//        客户编号	CustCode	Y	企业客户编号
            xmlTextWriter.writeElementString("CustCode",bankFront.org);
//        票据编号	BillCode	Y	30位电子票据编号
            xmlTextWriter.writeElementString("BillCode",query.detail.billNo);
//        备用字段1	reqReserved1
            xmlTextWriter.writeElementString("reqReserved1","");
//        备用字段2	reqReserved2
            xmlTextWriter.writeElementString("reqReserved2","");
//        备用字段3	reqReserved3
            xmlTextWriter.writeElementString("reqReserved3","");
//        备用字段4	reqReserved4
            xmlTextWriter.writeElementString("reqReserved4","");
            xmlTextWriter.writeEndDocument();
            String[] bankResult =sendToBank(xmlTextWriter.toXmlString());
            if(bankResult[0].length()==0){
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpSbReader = loadBankRespXmlReader(bankResult[1],tmpSbMsg);
            if(tmpSbReader!=null){
                String returnCode = tmpSbReader.getFirstText("/lcbank/head/RespCode");
                String returnInfo = tmpSbReader.getFirstText("/lcbank/head/RespInfo");
                String accpname = tmpSbReader.getFirstText("/lcbank/body/BillInfoQueryRespParam/AcceptBankName");
                retAts.writeRespCode(returnCode);
                retAts.writeRespInfo(returnInfo);
                if("0".equals(returnCode)){
                    while (tmpSbReader.read("/lcbank/body/BillInfoQueryRespParam/Details")){
//                        03:背书转让 12：质押
//                        04：贴现 14：提示付款de

                        String busiType =tmpSbReader.readedXElement.getSingleText("busType");
                        RetAtsB005BillBackQryDetail detailItem =new RetAtsB005BillBackQryDetail();
                        detailItem.respCode = "0";
                        if("03".equals(busiType)){
                            detailItem.transCode = "10";
                        }else if("04".equals(busiType)){
                            detailItem.transCode = "11";
                        }else if("12".equals(busiType)){
                            detailItem.transCode = "18";
                        }else if("14".equals(busiType)){
                            detailItem.transCode = "20";
                        }else{
                            continue;
                        }
                        String tranflag = tmpSbReader.readedXElement.getSingleText("Flag");
                        if(StringHelper.hasAnyChar(tranflag)){
                            detailItem.transFlag = "EM00".equals(tranflag)?"1":"0";
                        }
                        detailItem.applyName =tmpSbReader.readedXElement.getSingleText("ApplyName");
                        detailItem.receName =tmpSbReader.readedXElement.getSingleText("ReceName");
                        detailItem.applyDate =tmpSbReader.readedXElement.getSingleText("ApplyDate");
                        detailItem.respDate =tmpSbReader.readedXElement.getSingleText("RespDate");
                        if("14".equals(busiType)){
                            detailItem.receName =accpname;
                            //同意还是不同意
                            String resp = tmpSbReader.readedXElement.getSingleText("PayAndProtest");
                            if("SU00".equals(resp)) {
                                detailItem.respFlag = "1";
                            }else{
                                detailItem.respFlag = "2";
                                String unPayCode = tmpSbReader.readedXElement.getSingleText("Reason");
                                if(unPayCode.startsWith("DC0")){
                                    int code = Integer.valueOf(unPayCode.substring(3,4))+1;
                                    detailItem.unPayCode = code+"";
                                }else {
                                    detailItem.unPayCode = 99+"";
                                }
                            }
                        }else{
                            detailItem.respFlag = "1";
                        }
                        retAts.writeDetail(detailItem);
                    }
                }else{
                    throw new Exception(returnInfo);
                }
            }else{
                throw new Exception(tmpSbMsg.toString());
            }
            }else {
                throw new Exception(bankResult[1]);
            }

        }catch (Exception ex){
            ex.printStackTrace();
            retAts  = new RetAtsB005BillBackQry(query.reqHeader);
            retAts.writeStart();
            RetAtsB005BillBackQryDetail detail = new RetAtsB005BillBackQryDetail();
            detail.respCode="-1";
            detail.respInfo = ex.getMessage();
            retAts.writeDetail(detail);
        }
        retAts.writeEnd();
        return retAts;
    }

    @Override
    public RetAtsB006BillStateQry D_B006_BillState_Qeury(ReqB006BillStateQry query) throws Exception {
        RetAtsB006BillStateQry retAts = new RetAtsB006BillStateQry(query.reqHeader);
        retAts.writeStart();
        RetAtsB006BillStateQryDetail detail = new RetAtsB006BillStateQryDetail();
        try{
            while (query.readRecord()){
                if("1".equals(query.detail.operType)) {
                    int busiType = Integer.valueOf(query.detail.busiType);
                    switch (busiType) {
                        case 1:
//                            detail = QueryBillOpenApply(query.detail);
                            detail = BillExceptionQueryYf(query.detail);
                            break;
                        case 4:
//                            detail = QueryBillEndorse(query.detail);
                            detail = BillExceptionQueryYs(query.detail);
                        break;
                        case 5:
//                            detail = QueryBillPledgeApply(query.detail);
                            detail = BillExceptionQueryYs(query.detail);
                            break;
                        case 10:
//                            detail = QueryBillDiscountApply(query.detail);
                            detail = BillExceptionQueryYs(query.detail);
                            break;
                        case 12:
                            detail = BillExceptionQueryYs(query.detail);
                            break;
                        default: {
                            detail.respCode = "-1";
                            detail.respInfo = "银行暂不支持该查询功能";
                            detail.billNo = query.detail.billNo;
                        }
                    }
                }else if("2".equals(query.detail.operType)||"3".equals(query.detail.operType)){
                    detail = BillExceptionQueryDqs(query.detail);
                }
                else if("4".equals(query.detail.operType)&&"1".equals(query.detail.busiType)){
                    detail = BillExceptionQueryYf(query.detail);
                }
                retAts.writeDetail(detail);
            }
        }catch (Exception e){
            detail.respCode ="-1";
            detail.respInfo = e.getMessage();
            e.printStackTrace();
        }
        retAts.writeEnd();
        return retAts;
    }
    //持票操作状态查询
    private RetAtsB006BillStateQryDetail queryBillTips(ReqB006BillStateQryDetail detail) {
        RetAtsB006BillStateQryDetail respDetail = new RetAtsB006BillStateQryDetail();
        respDetail.billNo = detail.billNo;
        try{
            XmlTextWriter xmlTextWriter = new XmlTextWriter();
            LCBIP01Header header = new LCBIP01Header();
            header.TuxName = "QueryBillTips";
            header.ReqSeqNo =getQryTransID();
            writeCommonHeader(xmlTextWriter,header);
            xmlTextWriter.writeElementString("ReqReserved1","0",true);
            xmlTextWriter.writeElementString("ReqReserved2","50",true);
            xmlTextWriter.writeElementString("ReqReserved3","",true);
            xmlTextWriter.writeElementString("ReqReserved4","",true);
            xmlTextWriter.writeEndElement();
            xmlTextWriter.writeStartElement("body");
//            客户编号	CustCode	Y	集团签约模式：企业直连对接系统内部编号/财务公司编号
            xmlTextWriter.writeElementString("CustCode",bankFront.org);
//            查询类型	QueryType	Y	00：持票
            xmlTextWriter.writeElementString("QueryType","00");
//            票据类型	BillType	N	1：银行承兑汇票 2：商业承兑汇票
            xmlTextWriter.writeElementString("BillType",detail.billType);
//            票据形式	Pjxs	N	0: 纸质票据 1: 电子票据
            xmlTextWriter.writeElementString("Pjxs","1");
//            票据编号	BillCode	N
            xmlTextWriter.writeElementString("BillCode",detail.billNo);
//            开票日期（开始区间）	SDate	N	示例：20180101
            xmlTextWriter.writeElementString("SDate","",true);
//            开票日期（结束区间）	EDate	N	示例：20180631
            xmlTextWriter.writeElementString("EDate","",true);
//            到期日期（开始区间）	EndSDate	N	示例：20180101
            xmlTextWriter.writeElementString("EndSDate","",true);
//            到期日期（结束区间）	EndEDate	N	示例：20180631
            xmlTextWriter.writeElementString("EndEDate","",true);
//            票面金额（开始区间）	SAmt	N
            xmlTextWriter.writeElementString("SAmt","",true);
//            票面金额（结束区间）	EAmt	N
            xmlTextWriter.writeElementString("EAmt","",true);
//            时点日期（开始区间）	AccountSDate	N
            xmlTextWriter.writeElementString("AccountSDate","",true);
//            时点日期（结束区间）	AccountEDate	N
            xmlTextWriter.writeElementString("AccountEDate","",true);
//            票据状态	BillState	N	01:登记,02:库存,04:背书,05:贴现,06:质押,08:托收在途,09:托收到账
            xmlTextWriter.writeElementString("BillState","",true);
//            代保管方式	SafekeepStatus	N	0:否, 1:财务公司代保管, 2:银行代保管
            xmlTextWriter.writeElementString("SafekeepStatus","",true);
//            库存地点	StackPlace	N	1：财务公司北京
            xmlTextWriter.writeElementString("StackPlace","",true);
//            持票人账号	RecAcc	N
            xmlTextWriter.writeElementString("RecAcc","",true);
//            备用字段1	ReqReserved1 N	当前条数
            xmlTextWriter.writeElementString("ReqReserved1","0",true);
//            备用字段2	ReqReserved2 N	每页显示条数，默认显示50条
            xmlTextWriter.writeElementString("ReqReserved2","50",true);
//            备用字段3	ReqReserved3
            xmlTextWriter.writeElementString("ReqReserved3","",true);
//            备用字段4	ReqReserved4
            xmlTextWriter.writeElementString("ReqReserved4","",true);
            xmlTextWriter.writeEndDocument();
            String[] result =sendToBank(xmlTextWriter.toXmlString());
            if(result[0].length()==0) {
                StringBuilder tmpsbMsg = new StringBuilder();
                XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1],tmpsbMsg);//Status
                if(tmpbkReader!=null){
                    String returnCode = tmpbkReader.getFirstText("/lcbank/head/RespCode");
                    String returnInfo = tmpbkReader.getFirstText("/lcbank/head/RespInfo");
                    if("0".equals(returnCode)){
                        if(tmpbkReader.read("/lcbank/body/BillRecInfoRespParam")) {
                            respDetail.respCode = "0";
                            respDetail.respInfo = returnInfo;
                            respDetail.transState = "OpeStatus+" + tmpbkReader.readedXElement.getSingleText("OpeStatus");
                            respDetail.payInfoCode = respDetail.transState;
                        }
                    }else {
                        respDetail.respCode="-1";
                        respDetail.respInfo = returnInfo;
                    }
                }else {
                    respDetail.respCode = "-1";
                    respDetail.respInfo = tmpsbMsg.toString();
                }
            }else{
                respDetail.respCode = "-1";
                respDetail.respInfo = result[1];
            }
        }catch (Exception ex){
            ex.printStackTrace();
            respDetail.respCode = "-1";
            respDetail.respInfo =ex.getMessage();
        }
        return respDetail;
    }
        //待签收异常查询
    private RetAtsB006BillStateQryDetail BillExceptionQueryDqs(ReqB006BillStateQryDetail detail) {
        RetAtsB006BillStateQryDetail respDetail = new RetAtsB006BillStateQryDetail();
        respDetail.billNo = detail.billNo;
        try{
            XmlTextWriter xmlTextWriter = new XmlTextWriter();
            LCBIP01Header header = new LCBIP01Header();
            header.TuxName = "BillExceptionQueryDqs";
            header.ReqSeqNo =getQryTransID();
            writeCommonHeader(xmlTextWriter,header);
            xmlTextWriter.writeElementString("ReqReserved1","",true);
            xmlTextWriter.writeElementString("ReqReserved2","",true);
            xmlTextWriter.writeElementString("ReqReserved3","",true);
            xmlTextWriter.writeElementString("ReqReserved4","",true);
            xmlTextWriter.writeEndElement();
            xmlTextWriter.writeStartElement("body");
//            客户编号	CustCode	Y	集团签约模式：企业直连对接系统内部编号/财务公司编号 非集团签约模式：财务公司编号
            xmlTextWriter.writeElementString("CustCode",bankFront.org);
//            业务类型	BznsType	Y	02：提示承兑 03：正常收票 10：背书转让 12：贴现赎回 17：保证 19：质押解除 23：同意清偿
            String busitype;
            switch (Integer.valueOf(detail.busiType)){
                case 2:busitype="02";break;
                case 3:busitype="03";break;
                case 4:busitype="10";break;
                case 6:busitype="19";break;
                case 10:busitype="12";break;
                case 12:busitype="23";break;
                default:
                throw new Exception("未知的签收类型:"+detail.busiType);
            }
            xmlTextWriter.writeElementString("BznsType",busitype);
//            票据编号	BillCode
            xmlTextWriter.writeElementString("BillCode",detail.billNo);
//            出票人名称	DrawName
            xmlTextWriter.writeElementString("DrawName","",true);
//            币种	Curcd
            xmlTextWriter.writeElementString("Curcd","",true);
//            操作状态	Status		12A:允许发送银行, 12B:银行处理中, 12C:银行处理失败, 12D:银行处理成功, 20:处理完毕
            xmlTextWriter.writeElementString("Status","",true);
//            签收结果	PayoffResult		00：同意 01：拒绝
            xmlTextWriter.writeElementString("PayoffResult","",true);
//            出票日期开始	IssueDateS
            xmlTextWriter.writeElementString("IssueDateS","",true);
//            出票日期结束	IssueDateE
            xmlTextWriter.writeElementString("IssueDateE","",true);
//            到期日期开始	DateDueS
            xmlTextWriter.writeElementString("DateDueS","",true);
//            到期日期结束	DateDueE
            xmlTextWriter.writeElementString("DateDueE","",true);
//            票面金额开始	BillAmtS
            xmlTextWriter.writeElementString("BillAmtS","",true);
//            票面金额结束	BillAmtE
            xmlTextWriter.writeElementString("BillAmtE","",true);
//            备用字段1	ReqReserved1 reqReserved1
            xmlTextWriter.writeElementString("ReqReserved1","",true);
//            备用字段2	ReqReserved2 reqReserved2
            xmlTextWriter.writeElementString("ReqReserved2","",true);
//            备用字段3	ReqReserved3 reqReserved3
            xmlTextWriter.writeElementString("ReqReserved3","",true);
//            备用字段4	ReqReserved4 reqReserved4
            xmlTextWriter.writeElementString("ReqReserved4","",true);
            xmlTextWriter.writeEndDocument();
            String[] result =sendToBank(xmlTextWriter.toXmlString());
            if(result[0].length()==0) {
                StringBuilder tmpsbMsg = new StringBuilder();
                XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1],tmpsbMsg);//Status
                if(tmpbkReader!=null){
                    String returnCode = tmpbkReader.getFirstText("/lcbank/head/RespCode");
                    String returnInfo = tmpbkReader.getFirstText("/lcbank/head/RespInfo");
                    if("0".equals(returnCode)){
                        respDetail.respCode ="0";
                        respDetail.respInfo = tmpbkReader.getFirstText("/lcbank/head/RespInfo");
                        respDetail.transState ="Status+"+tmpbkReader.getFirstText("/lcbank/body/DqsExceptionRespParam/Status");
                        respDetail.payInfoCode = respDetail.transState;
//                        respDetail.reqSeqID = tmpbkReader.getFirstText("/lcbank/body/BillDisRespParam/ApplyCode");
                        respDetail.billState = "101";
                    }else {
                        respDetail.respCode="-1";
                        respDetail.respInfo = returnInfo;
                    }
                }else {
                    respDetail.respCode = "-1";
                    respDetail.respInfo = tmpsbMsg.toString();
                }
            }else{
                respDetail.respCode = "-1";
                respDetail.respInfo = result[1];
            }
        }catch (Exception ex){
            ex.printStackTrace();
            respDetail.respCode = "-1";
            respDetail.respInfo =ex.getMessage();
        }
        return respDetail;
    }
    //应收异常查询
    private RetAtsB006BillStateQryDetail BillExceptionQueryYs(ReqB006BillStateQryDetail detail) {
        RetAtsB006BillStateQryDetail respDetail = new RetAtsB006BillStateQryDetail();
        respDetail.billNo = detail.billNo;
        try{
            XmlTextWriter xmlTextWriter = new XmlTextWriter();
            LCBIP01Header header = new LCBIP01Header();
            header.TuxName = "BillExceptionQueryYs";
            header.ReqSeqNo =getQryTransID();
            writeCommonHeader(xmlTextWriter,header);
            xmlTextWriter.writeElementString("ReqReserved1","",true);
            xmlTextWriter.writeElementString("ReqReserved2","",true);
            xmlTextWriter.writeElementString("ReqReserved3","",true);
            xmlTextWriter.writeElementString("ReqReserved4","",true);
            xmlTextWriter.writeEndElement();
            xmlTextWriter.writeStartElement("body");
            String busi;
            if("4".equals(detail.busiType)){
                busi = "04";
            }else  if("5".equals(detail.busiType)){
                busi ="06";
            } else if("10".equals(detail.busiType)){
                busi ="05";
            } else{
                busi ="08";
            }
//            业务类型	Ywlx	Y	背书：04 贴现：05 质押：06 提示付款：08
            xmlTextWriter.writeElementString("Ywlx",busi);
//            客户编号	custCode	Y	集团签约模式：企业直连对接系统内部编号/财务公司编号 非集团签约模式：财务公司编号
            xmlTextWriter.writeElementString("custCode",bankFront.org);
//            操作状态	OpeStatus	Y	允许发送银行：12A 银行处理中：12B 银行处理失败：12C 银行处理成功12D
            xmlTextWriter.writeElementString("OpeStatus","",true);
//            撤销状态	RevokeStatus		撤销-允许发送银行：1A 撤销-银行处理中：1B 撤销-银行处理失败1C 撤销-银行处理成功1D
            xmlTextWriter.writeElementString("RevokeStatus","",true);
//            票据编号	BillCode
            xmlTextWriter.writeElementString("BillCode",detail.billNo);
//            票面金额开始	SpmjeS
            xmlTextWriter.writeElementString("SpmjeS","",true);
//            票面金额结束	SpmjeE
            xmlTextWriter.writeElementString("SpmjeE","",true);
//            出票日期开始	BillingDateS
            xmlTextWriter.writeElementString("BillingDateS","",true);
//            出票日期结束	BillingDateE
            xmlTextWriter.writeElementString("BillingDateE","",true);
//            到期日期开始	DateDueS
            xmlTextWriter.writeElementString("DateDueS","",true);
//            到期日期结束	DateDueE
            xmlTextWriter.writeElementString("DateDueE","",true);
//            发送日期开始	SendDateS
            xmlTextWriter.writeElementString("SendDateS","",true);
//            发送日期结束	SendDateE
            xmlTextWriter.writeElementString("SendDateE","",true);
//            备用字段1	ReqReserved1 reqReserved1
            xmlTextWriter.writeElementString("ReqReserved1","",true);
//            备用字段2	ReqReserved2 reqReserved2
            xmlTextWriter.writeElementString("ReqReserved2","",true);
//            备用字段3	ReqReserved3 reqReserved3
            xmlTextWriter.writeElementString("ReqReserved3","",true);
//            备用字段4	ReqReserved4 reqReserved4
            xmlTextWriter.writeElementString("ReqReserved4","",true);
            xmlTextWriter.writeEndDocument();
            String[] result =sendToBank(xmlTextWriter.toXmlString());
            if(result[0].length()==0) {
                StringBuilder tmpsbMsg = new StringBuilder();
                XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1],tmpsbMsg);//Status
                if(tmpbkReader!=null){
                    String returnCode = tmpbkReader.getFirstText("/lcbank/head/RespCode");
                    String returnInfo = tmpbkReader.getFirstText("/lcbank/head/RespInfo");
                    if("0".equals(returnCode)){
                        if(tmpbkReader.read("/lcbank/body/YsBillExceptionRespParam")) {
                            respDetail.respCode = "0";
                            respDetail.respInfo = returnInfo;
                            respDetail.transState = "OpeStatus+" + tmpbkReader.readedXElement.getSingleText("OpeStatus");
                            respDetail.payInfoCode = respDetail.transState;
                        }else {
                            respDetail = queryBillTips(detail);
                        }
                    }else {
                        respDetail.respCode="-1";
                        respDetail.respInfo = returnInfo;
                    }
                }else {
                    respDetail.respCode = "-1";
                    respDetail.respInfo = tmpsbMsg.toString();
                }
            }else{
                respDetail.respCode = "-1";
                respDetail.respInfo = result[1];
            }
        }catch (Exception ex){
            ex.printStackTrace();
            respDetail.respCode = "-1";
            respDetail.respInfo =ex.getMessage();
        }
        return respDetail;
    }
    //应付异常查询
    private RetAtsB006BillStateQryDetail BillExceptionQueryYf(ReqB006BillStateQryDetail detail) {
        RetAtsB006BillStateQryDetail respDetail = new RetAtsB006BillStateQryDetail();
        respDetail.billNo = detail.billNo;
        try{
            XmlTextWriter xmlTextWriter = new XmlTextWriter();
            LCBIP01Header header = new LCBIP01Header();
            header.TuxName = "BillExceptionQueryYf";
            header.ReqSeqNo =getQryTransID();
            writeCommonHeader(xmlTextWriter,header);
            xmlTextWriter.writeElementString("ReqReserved1","",true);
            xmlTextWriter.writeElementString("ReqReserved2","",true);
            xmlTextWriter.writeElementString("ReqReserved3","",true);
            xmlTextWriter.writeElementString("ReqReserved4","",true);
            xmlTextWriter.writeEndElement();
            xmlTextWriter.writeStartElement("body");
//            企业编号	CustCode	Y	集团签约模式：企业直连对接系统内部编号/财务公司编号 非集团签约模式：财务公司编号
            xmlTextWriter.writeElementString("CustCode",bankFront.org);
//            业务类型	Ywlx	Y	出票登记：KP 提示承兑：CD 提示收票：SP 撤票：CP
            xmlTextWriter.writeElementString("Ywlx","CP");
//            操作状态	OpeStatus		允许发送银行：2A
            xmlTextWriter.writeElementString("OpeStatus","");
//            承兑状态	PjyfkcCdzt		承兑-允许发送银行：1A
            xmlTextWriter.writeElementString("PjyfkcCdzt","");
//            提示收票状态	PjyfkcSpzt		提示收票-允许发送银行：1A
            xmlTextWriter.writeElementString("PjyfkcSpzt","");
//            票据编号	PjyfkcPjbh
            if("1".equals(detail.operType)&&"1".equals(detail.busiType)){
                xmlTextWriter.writeElementString("PjyfkcPjbh","");
            }else{
                xmlTextWriter.writeElementString("PjyfkcPjbh",detail.billNo);
            }

//            撤消状态	PjyfkcDpcxzt
            xmlTextWriter.writeElementString("PjyfkcDpcxzt","");
//            开票起始日期	billingDateS
            xmlTextWriter.writeElementString("billingDateS","");
//            开票结束日期	billingDateE
            xmlTextWriter.writeElementString("billingDateE","");
//            到期日起开始	dateDueS
            xmlTextWriter.writeElementString("dateDueS","");
//            到期日期结束	dateDueE
            xmlTextWriter.writeElementString("dateDueE","");
//            发送日起开始	sendDateS
            xmlTextWriter.writeElementString("sendDateS","");
//            发送日期结束	sendDateE
            xmlTextWriter.writeElementString("sendDateE","");
//            票面金额最小	pjyfkcPmjeS
            xmlTextWriter.writeElementString("pjyfkcPmjeS","");
//            票面金额最大	pjyfkcPmjeE
            xmlTextWriter.writeElementString("pjyfkcPmjeE","");
//            备用字段1	ReqReserved1 reqReserved1
            if("1".equals(detail.operType)&&"1".equals(detail.busiType)) {
                Connection conn  = FGBiz.getLocalDbConn();
                Map<String,Object> map =null;
                try {
                    map=JDBCHelper.execQuerySingle(conn,SELECTRECEIPT,new Object[]{detail.reqSeqID,"LCBIP01"});
                    xmlTextWriter.writeElementString("ReqReserved1",map.get("BANKREQSEQID").toString());
                }catch (Exception ex){
                    ex.printStackTrace();
                    respDetail.respCode ="-1";
                    respDetail.respInfo = ex.getMessage();
                    return respDetail;
                }finally {
                    conn.close();
                }
            }else{
                xmlTextWriter.writeElementString("ReqReserved1", "");
            }
//            备用字段2	ReqReserved2 reqReserved2
            xmlTextWriter.writeElementString("ReqReserved2","");
//            备用字段3	ReqReserved3 reqReserved3
            xmlTextWriter.writeElementString("ReqReserved3","");
//            备用字段4	ReqReserved4 reqReserved4
            xmlTextWriter.writeElementString("ReqReserved4","");

            xmlTextWriter.writeEndDocument();
            String[] result =sendToBank(xmlTextWriter.toXmlString());
            if(result[0].length()==0) {
                StringBuilder tmpsbMsg = new StringBuilder();
                XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1],tmpsbMsg);//Status
                if(tmpbkReader!=null){
                    String returnCode = tmpbkReader.getFirstText("/lcbank/head/RespCode");
                    String returnInfo = tmpbkReader.getFirstText("/lcbank/head/RespInfo");
                    if("0".equals(returnCode)){
                        if(tmpbkReader.read("/lcbank/body/YfBillExceptionRespParam")) {
                            respDetail.respCode = "0";
                            respDetail.respInfo = returnInfo;
                            if ("1".equals(detail.operType)) {
                                respDetail.transState = "PjyfkcPjzt+" + tmpbkReader.readedXElement.getSingleText("PjyfkcPjzt");
                            } else {
                                respDetail.transState = "PjyfkcCpzt+" + tmpbkReader.readedXElement.getSingleText("PjyfkcCpzt");
                            }
                            respDetail.payInfoCode = respDetail.transState;
                            respDetail.billNo = tmpbkReader.readedXElement.getSingleText("PjyfkcPjbh");
//                        respDetail.reqSeqID = tmpbkReader.getFirstText("/lcbank/body/BillDisRespParam/ApplyCode");
//                            respDetail.billState = "101";
                        } else {
                            respDetail = QueryBillInfor(detail);
                            }
                    }else {
                        respDetail.respCode="-1";
                        respDetail.respInfo = returnInfo;
                    }
                }else {
                    respDetail.respCode = "-1";
                    respDetail.respInfo = tmpsbMsg.toString();
                }
            }else{
                respDetail.respCode = "-1";
                respDetail.respInfo = result[1];
            }
        }catch (Exception ex){
            ex.printStackTrace();
            respDetail.respCode = "-1";
            respDetail.respInfo =ex.getMessage();
        }
        return respDetail;
    }
    //撤票信息结果查询
    private RetAtsB006BillStateQryDetail QueryBillInfor(ReqB006BillStateQryDetail detail) {
        RetAtsB006BillStateQryDetail respDetail = new RetAtsB006BillStateQryDetail();
        respDetail.billNo = detail.billNo;
        try{
            XmlTextWriter xmlTextWriter = new XmlTextWriter();
            LCBIP01Header header = new LCBIP01Header();
            header.TuxName = "QueryBillInfor";
            header.ReqSeqNo =getQryTransID();
            writeCommonHeader(xmlTextWriter,header);
            xmlTextWriter.writeElementString("ReqReserved1","0",true);
            xmlTextWriter.writeElementString("ReqReserved2","50",true);
            xmlTextWriter.writeElementString("ReqReserved3", "", true);
            xmlTextWriter.writeElementString("ReqReserved4","",true);
            xmlTextWriter.writeEndElement();
            xmlTextWriter.writeStartElement("body");
//            客户编号	CustCode	Y	集团签约模式：企业直连对接系统内部编号/财务公司编号
            xmlTextWriter.writeElementString("CustCode",bankFront.org);
//            查询类型	QueryType	Y	00：持票
            xmlTextWriter.writeElementString("QueryType","01");
//            票据类型	BillType	N	1：银行承兑汇票 2：商业承兑汇票
            xmlTextWriter.writeElementString("BillType",detail.billType);
//            票据形式	Pjxs	N	0: 纸质票据 1: 电子票据
            xmlTextWriter.writeElementString("Pjxs","1");
//            票据编号	BillCode	N
            if("1".equals(detail.operType)){
                xmlTextWriter.writeElementString("BillCode", "");
            }else {
                xmlTextWriter.writeElementString("BillCode", detail.billNo);
            }
//            开票日期（开始区间）	SDate	N	示例：20180101
            xmlTextWriter.writeElementString("SDate","",true);
//            开票日期（结束区间）	EDate	N	示例：20180631
            xmlTextWriter.writeElementString("EDate","",true);
//            到期日期（开始区间）	EndSDate	N	示例：20180101
            xmlTextWriter.writeElementString("EndSDate","",true);
//            到期日期（结束区间）	EndEDate	N	示例：20180631
            xmlTextWriter.writeElementString("EndEDate","",true);
//            票面金额（开始区间）	SAmt	N
            xmlTextWriter.writeElementString("SAmt","",true);
//            票面金额（结束区间）	EAmt	N
            xmlTextWriter.writeElementString("EAmt","",true);
//           票据合同号	Kpzbnm	N
            xmlTextWriter.writeElementString("Kpzbnm","",true);
//            收款人名称	Skrqc	N
            xmlTextWriter.writeElementString("Skrqc","",true);
//            票据状态	BillState	N	10:开票申请,11:开票申请提交,12:开票申请复核,13:开票申请退回,14:受理拒绝,22:已开票,42:已承付,7:作废,32:到期复核
            xmlTextWriter.writeElementString("BillState","",true);
//            备用字段1	ReqReserved1 N	当前条数
            xmlTextWriter.writeElementString("ReqReserved1","0",true);
//            备用字段2	ReqReserved2 N	每页显示条数，默认显示50条
            xmlTextWriter.writeElementString("ReqReserved2","50",true);
//            备用字段3	ReqReserved3
            Connection conn = FGBiz.getLocalDbConn();
            if("1".equals(detail.operType)&&"1".equals(detail.busiType)){
                try {
                    Map<String, Object> map = JDBCHelper.execQuerySingle(conn, SELECTRECEIPT, new Object[]{detail.reqSeqID, "LCBIP01"});
                    xmlTextWriter.writeElementString("ReqReserved3", map.get("BANKREQSEQID").toString(), true);
                } catch (Exception ex) {
                    ex.printStackTrace();
                    respDetail.respCode = "-1";
                    respDetail.respInfo = ex.getMessage();
                    return respDetail;
                } finally {
                    conn.close();
                }
            }else{
                xmlTextWriter.writeElementString("ReqReserved3", "", true);
            }
//            备用字段4	ReqReserved4
            xmlTextWriter.writeElementString("ReqReserved4","",true);
            xmlTextWriter.writeEndDocument();
            String[] result =sendToBank(xmlTextWriter.toXmlString());
            if(result[0].length()==0) {
                StringBuilder tmpsbMsg = new StringBuilder();
                XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1],tmpsbMsg);//Status
                if(tmpbkReader!=null){
                    String returnCode = tmpbkReader.getFirstText("/lcbank/head/RespCode");
                    String returnInfo = tmpbkReader.getFirstText("/lcbank/head/RespInfo");
                    if("0".equals(returnCode)){
                        if(tmpbkReader.read("/lcbank/body/BillInfoRespParam")) {
                            respDetail.respCode = "0";
                            respDetail.respInfo = returnInfo;
                            if("1".equals(detail.operType)) {
                                respDetail.transState = "Pjzt+" + tmpbkReader.readedXElement.getSingleText("Pjzt");
                            }else{
                                respDetail.transState = "Cpzt+" + tmpbkReader.readedXElement.getSingleText("Cpzt");
                            }
                            respDetail.payInfoCode = respDetail.transState;
                            respDetail.billNo =tmpbkReader.readedXElement.getSingleText("Pjbh");
                        }
                    }else {
                        respDetail.respCode="-1";
                        respDetail.respInfo = returnInfo;
                    }
                }else {
                    respDetail.respCode = "-1";
                    respDetail.respInfo = tmpsbMsg.toString();
                }
            }else{
                respDetail.respCode = "-1";
                respDetail.respInfo = result[1];
            }
        }catch (Exception ex){
            ex.printStackTrace();
            respDetail.respCode = "-1";
            respDetail.respInfo =ex.getMessage();
        }
        return respDetail;
    }


    @Override
    public RetAtsB007BillKzsrQry D_B007_BillKzsr_Query(ReqB007BillKzsrQry query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB008HistoricalBillQry D_B008_HistoricalBillQuery(ReqB008HistoricalBillQry query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB009DrawBillQry D_B009_DrawBillQuery(ReqB009DrawBillQry query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB010ProtocolStateQry D_B010_ProtocolStateQuery(ReqB010ProtocolStateQry query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB011TransFlagQry D_B011_TransFlagQuery(ReqB011TransFlagQry query) throws Exception {
        return null;
    }
}
